package com.learning.javaweb_servlet_jdbc;

import java.sql.*;

public class JDBCTest02 {

    static final String URL = "jdbc:mysql://localhost:3306/jdbc_demo?useSSL=false&serverTimezone=GMT&characterEncoding=UTF-8";
    static final String USER = "root";
    static final String PASSWORD = "WQ9ABCAT";
    static final String SQL = "select * from student";
    public static void main(String[] args) {
//语法糖模式——————————————————————————————————————————————————————————————————————————————————————————————————————

        // 加载mysql驱动
        try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);) {
            // 创建Statement对象
            try (PreparedStatement ps = conn.prepareStatement(SQL);) {
                // 声明要做查询操作
                try (ResultSet rs = ps.executeQuery();) {
                    while (rs.next()) {
                        System.out.println(rs.getObject(1)+" "+rs.getObject(2));
                    }
                }
            } catch (SQLException e) {
                conn.rollback();
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}